<template>
  <a-config-provider :locale="zhCN" :get-popup-container="getPopupContainer">
    <router-view v-if="appStore.$state.isRouterAlive" />
  </a-config-provider>
</template>

<script setup>
import zhCN from "ant-design-vue/es/locale/zh_CN";
import dayjs from "dayjs";
import "dayjs/locale/zh-cn";
import { nextTick, onBeforeUnmount, onMounted, provide } from "vue";
import { useAppStore } from "@/store/modules/appStore";
import { userStore } from "@/store/modules/userStore";
import WS from "@/utils/WS";

dayjs.locale(zhCN.locale);

const appStore = useAppStore();
const userstore = userStore();

const reload = () => {
  appStore.$patch({ isRouterAlive: false });
  nextTick(() => {
    appStore.$patch({ isRouterAlive: true });
  });
};
provide("reload", reload);

const getPopupContainer = (el, dialogContext) => {
  if (dialogContext) {
    return dialogContext.getDialogWrap() || document.body;
  } else if (el) {
    return el.parentNode || document.body;
  }
  return document.body;
};
onMounted(() => {
  WS.start();
});

onBeforeUnmount(() => {
  userstore.changeOperateList([]);
  WS.stop();
});
</script>
